package cn.chen.miaosha.dao;

import cn.chen.miaosha.domain.Goods;
import cn.chen.miaosha.domain.MiaoshaGoods;
import cn.chen.miaosha.vo.GoodsVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface GoodsDao {

    @Select("select g.*,mg.miaosha_price,mg.stock_count,mg.start_date,mg.end_date from miaosha_goods mg left join goods g on mg.id=g.id")
    List<GoodsVO> listGoodsVO();

    @Select("select g.*,mg.miaosha_price,mg.stock_count,mg.start_date,mg.end_date from miaosha_goods mg left join goods g on mg.id=g.id where g.id = #{goodsId}")
    GoodsVO getGoodsVOById(@Param("goodsId") long goodsId);

    @Update("update miaosha_goods goods set stock_count=stock_count-1 where goods.id = #{goodsId} and stock_count > 0")
    int reduceStock(MiaoshaGoods g);
}
